# Contributor: Edward E. <develinthedetail@gmail.com>

_realname=libde265
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.16
pkgrel=1
pkgdesc="Open h.265 video codec library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/strukturag/libde265"
msys2_references=(
  "cpe: cpe:/a:struktur:libde265"
)
license=('spdx:LGPL-3.0-or-later' 'spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-SDL2")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=("${MINGW_PACKAGE_PREFIX}-SDL2: for dec265 video output")
source=("https://github.com/strukturag/libde265/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-fix-VPATH.patch")
sha256sums=('b92beb6b53c346db9a8fae968d686ab706240099cdd5aff87777362d668b0de7'
            'b4cdce2b362fde574512c2fad2e479f27969c0fe4df241322d9915d189dcb763')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}"/001-fix-VPATH.patch

  ./autogen.sh
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  CPPFLAGS='-I$(top_srcdir)/libde265 -I$(top_srcdir) -I$(top_srcdir)/sherlock265' \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
 
  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
